package buttonDemo;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ButtonDemo implements ActionListener{

	JLabel jlab;
	ButtonDemo(){
		JFrame jfrm = new JFrame("Button Example");
		jfrm.setLayout(new FlowLayout());
		jfrm.setSize(220,100);
		jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JButton jbtnFirst = new JButton("First");
		jbtnFirst.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				jlab.setText("MouseEvent mouseReleased");
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				jlab.setText("MouseEvent mousePressed");
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				jlab.setText("MouseEvent mouseExited");
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				jlab.setText("MouseEvent mouseEntered");
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				jlab.setText("MouseEvent mouseClicked");
			}
		});
		JButton jbtnSecond = new JButton("Second");
		jbtnFirst.addActionListener(this);
		jbtnSecond.addActionListener(this);
		
		jfrm.add(jbtnFirst);
		jfrm.add(jbtnSecond);
		
		jlab = new JLabel("Press a button.");
		jfrm.add(jlab);
		jfrm.setVisible(true);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("First")){
			jlab.setText("First Buttom");
			
		}
		if(e.getActionCommand().equals("Second")){
			jlab.setText("Second Buttom");
		}
	}

}
